package com.study.seckill.web.api;

import com.study.dto.UserDTO;
import com.study.seckill.entity.CourseSeckillOrder;
import com.study.seckill.service.CourseService;
import com.study.seckill.util.MailTool;
import com.study.util.ResponseResult;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: Rabbithandler
 * @Author: wYin
 * @Date: 2022/3/11 16:39
 */
@RabbitListener(queues = {"wYin-dead-queue"})
@Component
public class RabbitEmailHandler {
    @Autowired
    private JavaMailSender javaMailSender;

    @Autowired
    private MailTool mailTool;

    @RabbitHandler
    public void receiving(CourseSeckillOrder courseSeckillOrder){
        //        String[] filePathList = new String[]{"文件地址1", "文件地址2", "文件地址3"};
        Map<String, Object> valueMap = new HashMap<String, Object>();
        valueMap.put("to", new String[]{"wyin12@qq.com"});
        valueMap.put("title", "课程订单详情");
        valueMap.put("orderNumber",courseSeckillOrder.getOrderNumber());
        valueMap.put("orderTime",courseSeckillOrder.getOrderTime());
        valueMap.put("seckillPrice",courseSeckillOrder.getSeckillPrice());
//        valueMap.put("filePathList", filePathList);
        mailTool.sendSimpleMail(valueMap);
//        System.out.println("消息是："+courseSeckillOrder);
//        SimpleMailMessage message = new SimpleMailMessage();
//        message.setFrom("2443551575@qq.com");
//        message.setTo("wyin12@qq.com");
//        message.setSubject("测试邮件");
//        String html = "<html><body><h4>订单编号为："+courseSeckillOrder.getOrderNumber()+"下单时间是："+courseSeckillOrder.getOrderTime()+"</h4" +
//                "></body" +
//                "></html>";
//        message.setText(html);
//        javaMailSender.send(message);

    }
}
